import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

class NavigationBarPage extends StatefulWidget {
  const NavigationBarPage({super.key});

  @override
  State<NavigationBarPage> createState() => _NavigationBarPageState();
}

class _NavigationBarPageState extends State<NavigationBarPage> {
  int _index = 0;


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("NavigationBar Demo")),
      body: const Center(child: Text("玛卡巴卡")),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Fluttertoast.showToast(msg: "点击中间的+号");
        },
        tooltip: '你想干什么',
        child: const Icon(
          Icons.add,
          color: Colors.white,
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: BottomAppBar(
        shape: const CircularNotchedRectangle(),
        child:  Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            Expanded(
              child: IconButton(
                icon: const Icon(Icons.home),
                tooltip: '首页',
                color: _index == 0 ?
                      Colors.blue :
                      Colors.blue.withOpacity(0.6),
                onPressed: () {
                  setState(() {
                    //手动赋值索引
                    _index = 0;
                  });
                },
              ),
            ),
            Expanded(
              child: IconButton(
                icon: const Icon(Icons.email),
                tooltip: '邮件',
                color:  _index == 1 ?
                      Colors.blue :
                      Colors.blue.withOpacity(0.6),
                onPressed: () {
                  setState(() {
                    _index = 1;
                  });
                },
              ),
            ),
            const Spacer(),
            Expanded(
              child: IconButton(
                icon: const Icon(Icons.av_timer),
                tooltip: '⏲',
                color:  _index == 2 ?
                      Colors.blue :
                      Colors.blue.withOpacity(0.6),
                onPressed: () {
                  setState(() {
                    _index = 2;
                  });
                },
              ),
            ),
            Expanded(
              child: IconButton(
                icon: const Icon(Icons.dashboard),
                tooltip: '组件',
                color:  _index == 3 ?
                      Colors.blue :
                      Colors.blue.withOpacity(0.6),
                onPressed: () {
                  setState(() {
                    _index = 3;
                  });
                },
              ),
            )
          ],
        )
      ),
    );
  }
}